package com.xhwl.logistics.component;

import com.xhwl.logistics.bo.cent.VehicleIntegratedConfigBO;
import com.xhwl.logistics.service.cent.QueryDeviceService;
import com.xhwl.logistics.service.impl.redis.VehicleIntegratedConfigRedisServiceImpl;
import com.xhwl.logistics.service.impl.redis.VehicleTokenRedisServiceImpl;
import com.xhwl.logistics.util.UploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

import java.util.List;

//@Component
public class InitRunner implements CommandLineRunner {

    @Autowired
    private VehicleIntegratedConfigRedisServiceImpl vehicleIntegratedConfigRedisService;

    @Autowired
    private VehicleTokenRedisServiceImpl vehicleTokenRedisService;

    @Autowired
    private QueryDeviceService queryDeviceService;

    @Override
    public void run(String... args) throws Exception {

        //初始化，使程序下载证书异常的网址图片时，可以正常访问
        UploadUtils.slovePKIX();

        List<VehicleIntegratedConfigBO> vehicleIntegratedConfigBOList = queryDeviceService.queryIntegratedConfigs();

        for (VehicleIntegratedConfigBO vehicleIntegratedConfigBO : vehicleIntegratedConfigBOList) {
            vehicleIntegratedConfigRedisService.insertOrUpdateVehicleIntegratedConfigForProjectId(vehicleIntegratedConfigBO);
            vehicleIntegratedConfigRedisService.insertOrUpdateVehicleIntegratedConfigForParkId(vehicleIntegratedConfigBO);

            vehicleTokenRedisService.insertOrUpdateToken(vehicleIntegratedConfigBO);
        }
    }
}
